<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="/resource/common.jsp"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>${title}</title>
		
		<style type="text/css">
			.td_title{width:70px; text-align: right; line-height: 30px}
		</style>
		<script type="text/javascript">
			function submitForm(){
				
				
				
				if($("#query_form").form('validate'))
				{
					if(checkcode()){
					//$("#parentName").val($("#parentId option:selected").text());
					top.mask();
					$("#query_form").ajaxSubmit({
						type:"post",
						dataType:"json",
						success:function(data){
							if(data.result == "1"){
								top.showMsg("名称不能重复");
								window.setTimeout(function(){
								$("#name").focus();
								top.unmask();
								},1500);
							}else{
								top.showMsg("保存成功");
								window.setTimeout(function(){
								top.unmask();
								top.refresh('afterSave');
								},1500);
							}
						},
						error:function(){
							alert();
							top.showMsg("错误");
							window.setTimeout(function(){
								top.unmask();
								},1000);
						}
					});
				}
					}
				
				
				
				
			}
			
			
			function checkcode(){
				var parentid = $("input[name='parentId']").val();
				var code = $("#code").val();
				var isok;
				//输入code时判断是否符合规定
				if(code.length>0){
				top.mask();
				var url = parent.formateUrl("dictionary/checkcode/@/#.json".replace("@", parentid).replace("#", code));
				$.ajax({
				type : "post",
				dataType : "json",
				async: false,//同步，不使用异步
				url : url,
				success : function(data) {
						if(data.result){
							top.unmask();
							isok= true;
						}else{
							
							top.showMsg("该编码已经存在，请重新输入！");
							window.setTimeout(function(){
								$("#code").focus();
								top.unmask();
								isok= false;
							},1500);							
						}
					},
					error : function() {
						top.showMsg("出错,请联系管理员");
						window.setTimeout(function(){
								top.unmask();
								isok= true;
							},1500);
					}
				});
				}else{
					isok= true;
				}
				return isok;
			}
			$(function(){
				
				
				
				$.post(
						"<c:url value='/dictionary/getname.json'/>",
						{
						},
						function(data){
							$('#parentId').combobox({    
							    data:data.list,
							    valueField:'dbId',    
							    textField:'name' ,
							    editable:false,
							    panelHeight:100,
							    onSelect:function (rec)
							    {
							    	$("#parentName").val(rec.name);
							    }
							    
							    
							}); 
						},
						"json"
					);
				
				
				/*
				$.post(
					"<c:url value='/dictionary/getname.json'/>",
					{
					},
					function(data){
						$.each(data.list,function(i,dict){
							$("#parentId").append("<option value='"+dict.dbId+"'>"+dict.name+"</option>");
						});
						
						//$("#parentId").addClass("easyui-combobox");
						document.getElementById("parentId").className='easyui-combobox';
					},
					"json"
				);
				*/
				$("body").css({visibility:"visible"});
				
			})
		</script>
	</head>


	<body >
		<form style="margin:0;padding: 0;" method="post" id="query_form" action="<c:url value='/dictionary/add.json'/>">
			<table>
				<tr>
					<td class="td_label">字典项:</td>
					<td>
						<select style="width:260px;" name="parentId" id="parentId"    data-options='required:true,tipPosition:"bottom",missingMessage:"请选择字典项"'>
							<option value="">请选择</option>
						</select>
						<input type="hidden" name="parentName" id="parentName"/>
					</td>
				</tr>
				<tr>
					<td class="td_label">字典值:</td>
					<td >
						<input class="easyui-validatebox" data-options='required:true,tipPosition:"bottom",missingMessage:"请输入字典值"'  style="width:254px;" maxlength="25" type="text" id="name" name="name"/>
					</td>
				</tr>
				<tr>
					<td class="td_label">编码:</td>
					<td >
						<input style="width:254px;" maxlength="2" type="text" id="code" name="code"/>
					</td>
				</tr>
				<tr>
					<td class="td_label">排序序号:</td>
					<td >
						<input class="easyui-numberbox" data-options='required:true,tipPosition:"bottom",missingMessage:"请输入数字"' style="width:254px;"   maxlength="5" type="text" id="orderNum" name="orderNum"/>
					</td>
				</tr>
				<tr>
					<td class="td_label">备注:</td>
					<td >
						<input style="width:254px;" maxlength="80" type="text" id="remark" name="remark"/>
					</td>
				</tr>
			</table>
		</form>
	</body>
</html>